﻿Imports Entities
Public Class CamionDAL
    Public Shared Function List() As List(Of CAMIONES)
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = From rec In bd.CAMIONES
                          Where rec.ACTIVO
                            Order By rec.PATENTE Ascending
                Return query.ToList
            End Using
        Catch ex As Exception
            Debug.Print("CamionDAL.List() " + ex.Message)
            Return Nothing
        End Try
    End Function
    Public Shared Function Create(ByVal zObject As CAMIONES) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                bd.CAMIONES.Add(zObject)
                bd.SaveChanges()
                Return True
            End Using
        Catch ex As Exception
            Debug.Print("CamionDAL.Create() " + ex.Message)
            Return False
        End Try
    End Function
    Public Shared Function Update(ByVal zObject As CAMIONES) As CAMIONES
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CAMIONES
                              Where rec.PATENTE = zObject.PATENTE
                              Select rec).Single

                query.DESCRIPCION = zObject.DESCRIPCION
                query.ACTIVO = zObject.ACTIVO
                bd.SaveChanges()
                Return query
            End Using
        Catch ex As Exception
            Debug.Print("CamionDAL.Update() " + ex.Message)
            Return Nothing
        End Try
    End Function
    Public Shared Function Delete(ByVal zId As String) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim del = (From rec In bd.CAMIONES
                          Where rec.PATENTE = zId
                          Select rec).Single

                del.ACTIVO = False
                bd.SaveChanges()
                Return True
            End Using
        Catch ex As Exception
            Debug.Print("CamionDAL.Delete() " + ex.Message)
            Return False
        End Try
    End Function
    Public Shared Function Exist(ByVal zId As String) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CAMIONES
                            Where rec.PATENTE = zId
                            Select rec).Count
                If query > 0 Then
                    Return True
                Else
                    Return False
                End If
            End Using
        Catch ex As Exception
            Debug.Print("CamionDAL.Exist() " + ex.Message)
            Return False
        End Try
    End Function

    Public Shared Function SearchById(ByVal zId As String) As CAMIONES
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CAMIONES
                           Where rec.PATENTE = zId And rec.ACTIVO
                           Select rec).SingleOrDefault
                Return query
            End Using
        Catch ex As Exception
            Debug.Print("CamionDAL.SearchById() " + ex.Message)
            Return Nothing
        End Try
    End Function
End Class
